module.exports = function(wss) {
    wss.on('connection', function connection(ws) {
        ws.on('message', function incoming(message) {
            console.log('received: %s', message)
            ws.send(`you said ${message}`)
        })
        ws.on('close', function close() {
            console.log('ws disconnected');
        })
        ws.send('you can say something, then click send button')
        setInterval(function() {
            if (Math.ceil(Math.random() * 10) > 7) {
                ws.send(`now, time is ${(new Date).toString()}`, function(err) {
                    if (err) {
                        console.log(err.message)
                    }
                })
            }
        }, 2000)
    })
}
